package syyrjx.controller;

import syyrjx.jdbc.QuestionDB;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ModifyQuestionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.Modify(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.Modify(request, response);
    }

    private void Modify(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        String question = request.getParameter("question");
        String optionA = request.getParameter("optionA");
        String optionB = request.getParameter("optionB");
        String optionC = request.getParameter("optionC");
        String optionD = request.getParameter("optionD");
        String answer = request.getParameter("answer");
        QuestionDB qdb = new QuestionDB();
        if(qdb.modify(id,question,optionA,optionB,optionC,optionD,answer)){
            request.setAttribute("modifyRes","修改成功");
        }else{
            request.setAttribute("modifyRes","修改失败");
        }
        request.getRequestDispatcher("/queModifyResult.jsp").forward(request,response);
    }
}
